<template>
  <view class="cart-container">
    <view class="cart-exeit" v-if="cartList.length">
      <!-- 地址栏 -->
      <my-address></my-address>
      <view class="cart_title">
        <uni-icons type="shop" size="18"></uni-icons>
        <text>购物车</text>
      </view>

      <uni-swipe-action>
        <block v-for="(item, index) in cartList" :key="index">
          <uni-swipe-action-item :right-options="options" @click="delteGoods(item)">
            <my-goods @num-change="handleNumChange" :numberBox="true" @radioChange="radioChange2" :goods="item"
              :selected="true"></my-goods>
          </uni-swipe-action-item>
        </block>
      </uni-swipe-action>

      <my-settle></my-settle>
    </view>
    <view class="not-exeit" v-else>
      <image src="@/static/cart_empty@2x.png"></image>
      <text>空空如也~</text>
    </view>
  </view>
</template>

<script>
  import setBadge from '@/mixin/tabBarBadge.js'
  import {
    mapGetters,
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#C00000'
          }
        }]
      };
    },
    mixins: [setBadge],
    computed: {
      ...mapState('cart', ['cartList'])
      // ...mapGetters('cart', ['total'])
    },
    methods: {
      ...mapMutations('cart', ['changeState', 'chageNum', 'delGoodsItem']),
      radioChange2(e) {
        const obj = e
        this.changeState(obj)
      },
      handleNumChange(e) {
        this.chageNum(e)
      },
      delteGoods(goods) {
        this.delGoodsItem(goods)
      },
      // setBadge() {
      //   uni.setTabBarBadge({
      //     index: 2,
      //     text: this.total.toString()
      //   })
      // }
    }
  }
</script>

<style lang="scss">
  .cart-container {
    background-color: #fff;
    padding-bottom: 50px;
  }

  .cart_title {
    padding: 0 5px;
    height: 40px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #afafaf;

    text {
      margin-left: 7px;
    }
  }
  
  // cartList不存在时的样式
  .not-exeit{
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 150px;
    image{
      width: 90px;
      height: 90px;
    }
    text{
      margin-top: 15px;
      font-size: 12px;
      color: gray
    }
  }
</style>